<template>
  <div>
    <div id="one-box">
      <h3 class="h3-title margin">
        <span>当前等级: </span>
        <span class="color-red">LV.{{ leveConfig.level }}</span>
      </h3>
      <Step :count="stepConfig.count" :colorCount="stepConfig.colorCount" />
      <p class="level-text">等级数据每天下午2点更新</p>
      <h3 class="h3-title margin level-tq">
        <span>当前等级特权: </span>
        <ul v-if="leveConfig.info.length > 0 && leveConfig.info[0]">
          <li v-for="(item, index) in leveConfig.info" :key="index">
            {{ item }}
          </li>
        </ul>
        <ul v-else>
          <li>没有任何特权，加油升级哦!</li>
        </ul>
      </h3>
      <div class="info-level">
        <router-link to="/myGrades/info">了解等级特权></router-link>
      </div>
      <h3 class="h3-title margin footer-title">
        <span class="title">距离下一等级: </span>
        <span class="color-red"
          ><span class="ver">LV.{{ leveConfig.level + 1 }}</span>
          <i class="iconfont ver tag-icon"
            >&#xe7f3;

            <div class="warning-box">
              <p>
                听歌量是指累计播放的歌曲数量而非播放次数，并且实际播放时间过短的歌曲将不纳入计算，每天最多计算300首。
              </p>
              <p>
                登录天数是指使用云音乐的天数，在多端同时使用不会被重复计算。
              </p>
            </div>
          </i>
        </span>
      </h3>
      <!--  -->
      <div class="footer-music">
        <span>听歌:</span>
        <el-progress
        :stroke-width="4"
          class="width-100"
          :percentage="nowPlayCount"
          status="exception"
        ></el-progress>
        <span>还需听{{nextPlayCount}}首</span>
      </div>
      <div class="footer-music">
        <span>登录:</span>
        <el-progress
        :stroke-width="4"
          class="width-100"
          :percentage="nowLoginCount"
          status="exception"
        ></el-progress>
        <span>还需登录{{nextLoginCount}}</span>
      </div>
    </div>
  </div>
</template>

<script>
import { userLevel } from "@/api";
import Step from "@/components/step";
export default {
  name: "myGrades",
  components: {
    Step,
  },
  data() {
    return {
      stepConfig: {
        count: 10,
        colorCount: 0,
      },
      leveConfig: {
        info:"",
        level: 0, 
        nextLoginCount: 100, 
        nowLoginCount: 100,
        nextPlayCount: 100,
        nowPlayCount: 100,
        progress: 100,
        userId: 100,
        // info:
        //   "60G音乐云盘免费容量$黑名单上限80$云音乐商城满100减9元优惠券$价值400云贝", //信息
        // level: 7, // 等级
        // nextLoginCount: 100, // 剩余登录天数
        // nowLoginCount: 100, // 现在登录天数  总2000
        // nextPlayCount: 100, // 剩余播放量
        // nowPlayCount: 100, // 现在播放数量  总2000
        // progress: 100, // 当前进度
        // userId: 100, // 用户ID
      },
    };
  },
  computed: {
    nowLoginCount() {
      let result = this.leveConfig.nowLoginCount + this.leveConfig.nextLoginCount
      let yu = result - this.leveConfig.nextLoginCount
      return (100 / (result / yu))
    },
    nextLoginCount(){
      return this.leveConfig.nextLoginCount + "天"
    },
    nowPlayCount(){
      let result = this.leveConfig.nowPlayCount + this.leveConfig.nextPlayCount
      let yu = result - this.leveConfig.nextPlayCount
      return (100 / (result / yu))
    },
    nextPlayCount(){
      return this.leveConfig.nextPlayCount
    }
  },
  created() {
    this.init();
  },
  methods: {
    init() {
      userLevel().then((data) => {
        this.leveConfig = data.data;
        this.leveConfig.info = this.leveConfig.info
          .split("$")
          .map((item) => item);
        this.stepConfig.colorCount =
          this.stepConfig.count - this.leveConfig.level;
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.footer-music {
  font-size: 12px;
  margin-top:10px;
  .width-100 {
    margin:0 10px;
    width: 160px;
    display: inline-block;
    /deep/ .el-progress-bar{
      padding-right:0;
    }
    /deep/ .el-progress__text {
      display: none;
      width:0px;
    }
  }
}
.footer-title {
  .ver {
    vertical-align: middle;
  }
  .tag-icon {
    color: rgb(153, 153, 153);
    cursor: pointer;
    margin-left: 4px;
    &:hover {
      .warning-box {
        display: block;
      }
    }
  }
  position: relative;
  margin-top: 20px;
  .title {
    font-size: 15px;
  }
  .color-red {
    font-size: 17px;
  }
  .warning-box {
    cursor: text;
    &:hover {
      display: block;
    }
    font-weight: 400;
    display: none;
    border-radius: 4px;
    box-shadow: 0 0 3px #000;
    padding: 10px;
    box-sizing: border-box;
    position: absolute;
    left: 100px;
    width: 300px;
    font-size: 12px;
    line-height: 20px;
    background-color: #fff;
    color: #666;
    z-index:1;
    &::before {
      content: "";
      position: absolute;
      top: -10px;
      background-color: rgba(0, 0, 0, 0);
      height: 10px;
      left: 0;
      right: 0;
    }
  }
}
a,
a:active,
a:focus,
a:hover,
a:visited {
  color: #0e73ba;
}
.info-level {
  font-size: 12px;
  margin: 30px 0 0 0;
  padding-bottom: 25px;
  border-bottom: 1px solid #ddd;
  a:hover {
    color: #0e73ba !important;
    text-decoration: revert;
  }
}
.level-tq {
  margin-top: 20px;
  ul {
    li {
      margin-left: 4px;
      font-size: 14px;
      color: #666;
    }
    li::before {
      content: "\02022";
      color: #f00;
      margin-right: 4px;
    }
  }
}
.level-text {
  color: #999;
  margin-top: 4px;
  font-size: 12px;
}
#one-box {
  padding: 70px;
}
.h3-title {
  line-height: 32px;
  color: #333;
  font-size: 22px;
  .color-red {
    font-family: Arial;
    font-style: italic;
    font-weight: 600;
    color: #e03a24;
  }
}
</style>